package org.lab.tracecash.matchers;

import org.apache.commons.lang.Validate;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.lab.tracecash.model.Transaction;

public class TransactionNameMatcher extends BaseMatcher<String> {

	private final String desc;

	public TransactionNameMatcher(String desc) {
		Validate.notNull(desc);
		this.desc = desc;
	}

	@Override
	public boolean matches(Object item) {
		boolean result = false;
		if (item != null) {
			if (Transaction.class.isAssignableFrom(item.getClass())) {
				Transaction entity = (Transaction) item;
				if (desc.equals(entity.getDesc())) {
					result = true;
				}
			}
		}
		return result;
	}

	@Override
	public void describeTo(Description description) {
		description.appendText("no coindide con el valor " + desc);
	}

}
